
*Table A13 

clear


	foreach b in 5 1 2 3 6 {


	* Identify model with best fit
		forvalues v =1(1)5 {
			qui: insheet using "${data}v`b'_Parameters_`v'.csv"
			qui: destring v7, replace force
			qui: destring v8, replace force

			qui: su v7 if _n ==1
			qui: global lv`v' : di %4.1f `r(mean)'
			qui: su v8 if _n ==1
			qui: global flag`v' = `r(mean)'

			qui: clear
		}
		qui:set obs 5
		qui:ge loss =.
		qui:ge flag =.

		qui:ge sim = _n
		forvalues v =1(1)5 {
		qui: replace loss = ${lv`v'} if sim == `v'
		qui: replace flag = ${flag`v'} if sim == `v'
		}
		gsort loss sim
		su sim if _n ==1
		global best1 =    `r(mean)'


		clear
		
		* Table with all parameters
		forvalues v =1(1)5 {
			qui: insheet using "${data}v`b'_Parameters_`v'.csv"
			keep v1 
			drop if _n >7
			destring v1, replace force
			rename v1 sim`v'
			ge id =_n
			tempfile parameters`v' 
			save `parameters`v'' 
			clear
			
			insheet using "${data}v`b'_Parameters_`v'.csv"
			keep v2 
			drop if _n >11
			rename v2 sim`v'
			ge id =_n
			tempfile moments`v' 
			save `moments`v'' 
			clear
		}
		
		
		use `parameters1'
		forvalues v =2(1)5 {
			merge 1:1 id using `parameters`v'' 
			drop _merge
		}
		
		save "${data}v`b'_allparameters.dta", replace
		clear
		
		use `moments1'
		forvalues v =2(1)5 {
			merge 1:1 id using `moments`v'' 
			drop _merge
		}
		save "${data}v`b'_allmoments.dta", replace
		clear
		


		
		
		* Moment fit
		insheet using "${data}v`b'_Moments_all_${best1}.csv"
		
	
	
		ge moment = _n
		drop if moment >16 

		ge m= 1 if moment <5
	replace m = 2 if moment >4 & moment <9 
	replace m = 3 if moment >8  &moment <13
	replace m = 4 if moment >12 



	su v1 if _n ==1
	global a1_a_m`b' = `r(mean)'

	su v1 if _n ==2
	global a1_b_m`b' = `r(mean)'

	su v1 if _n ==3
	global a1_c_m`b' = `r(mean)'

	su v1 if _n ==4
	global a1_d_m`b' = `r(mean)'

	su v1 if _n ==5
	global a2_a_m`b' = `r(mean)'

	su v1 if _n ==6
	global a2_b_m`b' = `r(mean)'

	su v1 if _n ==7
	global a2_c_m`b' = `r(mean)'

	su v1 if _n ==8
	global a2_d_m`b' = `r(mean)'

	su v1 if _n ==9
	global x_a_m`b' = `r(mean)'

	su v1 if _n ==10
	global x_b_m`b' = `r(mean)'

	su v1 if _n ==11
	global x_c_m`b' = `r(mean)'

	su v1 if _n ==12
	global x_d_m`b' = `r(mean)'

	su v1 if _n ==13
	global s_a_m`b' = `r(mean)'

	su v1 if _n ==14
	global s_b_m`b' = `r(mean)'

	su v1 if _n ==15
	global s_c_m`b' = `r(mean)'




	clear



	insheet using "${data}v`b'_Parameters_${best1}.csv"
	

	destring v2, replace force
	su v2 if _n ==3
	local a2_c_m`b' = `r(mean)'
	su v2 if _n ==4
	local a2_d_m`b' = `r(mean)'
	keep v1 
	drop if _n >7

	destring v1, replace force
	
	

	forvalues v = 1(1)7{
		su v1 if _n == `v'
		local r`v'_m`b' : di %4.1f `r(mean)'
	}

	


	local r8_m`b' : di %4.2f (`r2_m`b''+ (`r1_m`b'' * `a2_c_m`b'')) / (`r2_m`b'') -1
	local r9_m`b' : di %4.2f (`r2_m`b''+ (`r1_m`b'' * `a2_d_m`b'')) / (`r2_m`b'') -1
	local r10_m`b' : di %4.1f  (`r3_m`b'') * (${a1_d_m`b'})^2
	local r11_m`b' : di %4.1f  (`r4_m`b'') * (${a2_d_m`b'})^2
	local r8_m`b'  = `r8_m`b''*100
	local r9_m`b' = `r9_m`b''*100
	display `r8_m`b''
	display ${a2_c}
	display ${a2_d}


	
	clear

	insheet using "${data}v`b'_Moments_all_${best1}.csv"
	destring v1, replace force
	su v1 if _n ==13
	global r13_c2  : di %4.2f `r(mean)'

	su v1 if _n ==14
	global r14_c2 : di %4.3f `r(mean)'

	su v1 if _n ==15
	global r15_c2 : di %4.3f `r(mean)'
	

	
	clear
	
	insheet using "${data}v`b'_Parameters_${best1}.csv"
	
	
	
	
	destring v7, replace force
	su v7 if _n ==1
	local loss1_m`b' : di %4.1f `r(mean)'

	keep v2 v3
	drop if _n >12
	rename v2 simulated
	rename v3 real
	destring simulated, replace force
	destring real, replace force
	forvalues v = 1(1)12{
	su simulated if _n == `v'
	local r`v'_c2_m`b' : di %4.3f  `r(mean)'
		su real if _n == `v'
	local r`v'_c1 : di %4.3f `r(mean)'
	}


	display "Here I am : version `b'"
	clear
}


clear
set obs 6
ge loss_function =.
ge gamma = .
ge marginal1 = .
ge marginal2 = .
ge output_shared =. 
ge output_worker =. 
ge output_supv =.
ge output_control =.

local l = 0
	foreach b in  5 1 2 3 6 {
		local l = `l'+1
		replace loss_function = `loss1_m`b''  if _n == `l'
		replace gamma = `r1_m`b'' if _n == `l'
		replace marginal1 = `r8_m`b'' if _n == `l'
		replace marginal2 = `r9_m`b'' if _n == `l'
		replace output_worker= `r5_c2_m`b'' if _n == `l'
		replace output_supv = `r6_c2_m`b'' if _n == `l'
		replace output_shared = 	`r7_c2_m`b'' if _n == `l'
		replace output_control = `r8_c2_m`b'' if _n == `l'
	}
	
	ge diff_worker = output_shared  - output_worker
	ge diff_supv = output_shared  - output_supv
	
local l = 0
	foreach b in  5 1 2 3 6  {
		local l = `l'+1
		su marginal1 if _n == `l'
		local r1_c`l' : di %4.0f   `r(mean)'
		su marginal2 if _n == `l'
		local r2_c`l' : di %4.0f   `r(mean)'
		su diff_worker if _n == `l'
		local r3_c`l' : di %4.3f   `r(mean)'
		su diff_supv if _n == `l'
		local r4_c`l' : di %4.3f   `r(mean)'
		su loss_function if _n == `l'
		local r5_c`l' : di %4.2f   `r(mean)'

	}
	



	#delimit ;	
	file open myfile using "${output}TableA13.tex", write replace;
	file write myfile   _n "\begin{tabular}{lccccc}"			
	_n "\thickhline"
	_n "Moments &  Headline & \multicolumn{4}{c}{Alternative } \\"
	_n " &   &  1 & 2  &  3  &  4   \\"
	_n "\hline"		
	_n "\mbox{}\\"
	_n " \$ \Delta\$ in marginal product of worker effort (shared incentive) & `r1_c1'\% & `r1_c2'\%   & `r1_c3'\% & `r1_c4'\% & `r1_c5'\%   \\ "	
	_n " \$ \Delta\$ in marginal product of worker effort 	(no incentive)		    &`r2_c1'\%  & `r2_c2'\% & `r2_c3'\%  & `r2_c4'\%  & `r2_c5'\%    \\ "
	_n " Visits in \$T_{shared}\$ - visits in \$T_{worker}\$  & `r3_c1'  & `r3_c2'  & `r3_c3' & `r3_c4'  & `r3_c5'   \\ "	
	_n " Visits in \$T_{shared}\$ - visits in \$T_{supv}\$   &`r4_c1' & `r4_c2' & `r4_c3' & `r4_c4' & `r4_c5'   \\	"
	_n "\thickhline"
	_n "\end{tabular}" 
	_n " \mbox{}\\" 
	_n "\footnotesize"
	_n " Notes: The table shows estimated parameters and simulated moments for different assumptions on the reporting threshold used in \$T_{shared}\$ and \$T_{worker}\$. Headline: workers in \$T_{worker}\$ use the non-strategic threshold, workers in \$T_{shared}\$ use a threshold that is 10 percent higher than the non-strategic threshold. Alternative 1: workers in  \$T_{worker}\$ and \$T_{shared}\$ use the non-strategic threshold. Alternative 2:  workers in  \$T_{worker}\$ and \$T_{shared}\$ use a threshold that is 10 percent higher than the non-strategic threshold.  Alternative 3:  workers in  \$T_{worker}\$ and \$T_{shared}\$ use a threshold that is 20 percent higher than the non-strategic threshold. Alternative 4: workers in \$T_{worker}\$ use a threshold that is 10 percent higher than the non-strategic threshold, workers in \$T_{shared}\$ use a threshold that is 20 percent higher than the non-strategic threshold. ";
	file close myfile;
	#delimit cr


 
